<?php
/*
	账户支付
	管理端支付接口
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('没有找到该讲座，请重新选择！','error','jy_zhongyi/baoming.index/list');
	}
	$num=pdo_getcolumn('jy_zhongyi_baoming_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'readnum');
	$num=$num+1;
	pdo_update('jy_zhongyi_baoming_list',array('readnum'=>$num),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$activity=pdo_get('jy_zhongyi_baoming_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$num1=pdo_count('jy_zhongyi_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>1));
	$num2=pdo_count('jy_zhongyi_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>2));
	$num3=pdo_count('jy_zhongyi_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>4));
	$activity['num']=$num1+$num2+$num3;
	$this->session('activity_id',$_RQ['id']);
	$return['activity']=$activity;
	$return['banner']=json_decode($activity['hdp'],true);
	$return['sharedata']=array(
		'title'=>$activity['title'],
		'desc'=>$activity['remark'],
		'link'=>custom_url('jy_zhongyi/baoming.detail//id='.$activity['id'],true),
		'imgUrl'=>ATTACHMENT_URL.$activity['image'],
	);
	set_html('title',$activity['title']);
	$return['post']=array();
	exi($return);
}
if($_RQ['op']=='notice'){
	$postdata=get_postdata();
	$activity_id = $this->session('activity_id');
	$activity=pdo_get('jy_zhongyi_baoming_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$activity_id));
	//是否超过报名截止时间
	if(time()-strtotime($activity['end'])>0){
		exi('已过预约截止时间，该讲座报名人数已满，请选择其他讲座报名','error','jy_zhongyi/index/');
	}
	//是否重复提交
	$order=pdo_get('jy_zhongyi_baoming_order',array('user_id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status in'=>array(1,2,4)));
	if($order){
		exi('您已预约过该讲座，请选择其他讲座报名','error','jy_zhongyi/index/');
	}
	$num1=pdo_count('jy_zhongyi_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>1));
	$num2=pdo_count('jy_zhongyi_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>2));
	$num3=pdo_count('jy_zhongyi_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>4));
	$sum=$num1+$num2+$num3;
	if($activity['mannum']-$sum <= 0){
		exi('该讲座报名人数已满，请选择其他讲座报名','error','jy_zhongyi/index/');
	}
	//判断是否有数据
	if(empty($postdata['name'])){
		exi('请填写姓名','error');
	}
	if(empty($postdata['mobile'])){
		exi('请填写手机号码','error');
	}
	if(!preg_match("/^1[345678]{1}\d{9}$/",$postdata['mobile'])){  
	 
		exi('请输入正确的手机号码','error');
	} 
	if($postdata){
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'user_id'=>$_SESSION['uid'],
			'activity_id'=>$this->session('activity_id'),
			'money'=>$activity['money'],
			'name'=>$postdata['name'],
			'mobile'=>$postdata['mobile'],
			'remark'=>trim($postdata['remark']),
			'ordersn'=>get_ordersn('jy_zhongyi_baoming_order','ordersn'),
			'createtime'=>TIMESTAMP,
		);
		//	exi($insert,'error');
		pdo_insert('jy_zhongyi_baoming_order',$insert);
		$id=pdo_insertid();
	}
	//exi('提交订单');
	exi('','','jy_zhongyi/baoming.book/main/id='.$id);
}
if($_RQ['op']=='check_buy'){
	$activityid=$_RQ['activityid']?:$activityid;
	if(!$activityid){
		exi('请选择讲座','error');
	}
	exi('','','jy_zhongyi/baoming.book//activityid='.$activityid);
}
